package com.programmercarl.array;

/**
 * https://leetcode.cn/problems/valid-perfect-square/
 *
 * @author yulongtian
 * @create 2024-12-10 12:17
 */
public class Test05 {
    public static void main(String[] args) {

    }

    public boolean isPerfectSquare(int num) {
        long left = 0L;
        long right = num;
        while (left <= right) {
            long mid = left + ((right - left) / 2);
            if (mid * mid > num) {
                right = mid - 1;
            } else if (mid * mid < num) {
                left = mid + 1;
            } else {
                return true;
            }
        }

        return false;
    }
}
